/**
 *
 * @param table {Table}
 * @param auth {boolean} 接口是否需要鉴权
 * @param uninstall {boolean} 是否在生成代码时注释该方法，用于备用
 * @returns {string}
 */
const findById = (table, auth = false, uninstall = false) => {
  const {
    comment,
    idType,
    date,
    author,
    names: {TabName}
  } = table
  const ordered = table.incrementAndGetOrdered()
  return `// <-
    @GetMapping("/{encryptId}")
    //@PreAuthorize("hasAnyAuthority('ROLE_ADMIN', 'ROLE_ADMIN_TEST', '{}_load')")
    @ApiOperation(value = "${ordered}.按 id 查询${comment}", tags = {""})
    @ApiOperationSupport(order = ${ordered}, author = "${author}") 
    @ResponseBody
    public Result<${TabName}> findById(
            @ApiIgnore @AuthenticationPrincipal final IUser user,
            @ApiParam(required = true, value = "加密id", example = "encryptId") @PathVariable final String encryptId
    ) {
        return new Result<${TabName}>().execute(result -> { // Controller 方法逻辑写在这里
            final AesApiId.AesId decrypt = AesApiId.decrypt(encryptId);
            result.setSuccess(service.findById(decrypt.get${idType}Id()).orElse(null));
        });
    }
`.split('\n')
    .map(row => (uninstall ? '//' : '') + row)
    .join('\n')
}
export const findByIdOpenInstall = table => findById(table)
export const findByIdOpenUninstall = table => findById(table, false, true)

export const findByIdAuthInstall = table => findById(table, true, false)
export const findByIdAuthUninstall = table => findById(table, true, true)
